package com.farmUni.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farmUni.common.R;
import com.farmUni.entity.Vo.ArticleAddVO;
import com.farmUni.entity.Vo.ArticleDetailVO;
import com.farmUni.entity.Vo.ArticleShowVO;
import com.farmUni.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wxy
 * @since 2024-02-04
 */
@Slf4j
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/user/getShowList")
    public R<Page<ArticleShowVO>> getShowList(int current, int size){
        return R.success(articleService.getShowList(current,size));
    }

    @GetMapping("/user/getShowList/plus")
    public R<Page<ArticleShowVO>> getShowListPlus(int current, int size,String matching){
        return R.success(articleService.getShowListPlus(current,size,matching));
    }

    @GetMapping("/recArticle")
    public R<List<ArticleShowVO>> getRecArticle(){
        return R.success(articleService.getRecArticle());
    }


    @GetMapping("/topArticle")
    public R<List<ArticleShowVO>> getTopArticle(){
        return R.success(articleService.getTopArticle());
    }

    @GetMapping("/getMarket")
    public R<List<ArticleShowVO>> getMarket(){
        return R.success(articleService.getMarket());
    }

    @GetMapping("/getFrontier")
    public R<List<ArticleShowVO>> getFrontier(){
        return R.success(articleService.getFrontier());
    }

    @GetMapping("/getPolicy")
    public R<List<ArticleShowVO>> getPolicy(){
        return R.success(articleService.getPolicy());
    }

    @GetMapping("/getMedication")
    public R<List<ArticleShowVO>> getMedication(){
        return R.success(articleService.getMedication());
    }

    @GetMapping("getEducation")
    public R<List<ArticleShowVO>> getEducation(String edu){
        return R.success(articleService.getEducation(edu));
    }

    @PostMapping("/add")
    public R<String> add(@RequestBody ArticleAddVO articleAddVO){
        Boolean isSuccess = articleService.add(articleAddVO);
        return isSuccess?R.success("添加成功"):R.error("添加失败");
    }

    @GetMapping("/getDetail")
    public R<ArticleDetailVO> getDetail(Long id){
        return R.success(articleService.getDetail(id));
    }

    @GetMapping("/getCultureOrImpressRec")
    public R<List<ArticleShowVO>> getCultureOrImpressRec(String type){
        return R.success(articleService.getCultureOrImpressRec(type));
    }

    @GetMapping("/getMyPage")
    public R<Page<ArticleShowVO>> getMyPage(int current, int size){
        return R.success(articleService.getMyPage(current,size));
    }

    @PostMapping("/removeById")
    public R<String> removeById(Long id){
        boolean isSuccess = articleService.removeById(id);
        return isSuccess?R.success("删除成功"):R.error("删除失败");
    }

    @PostMapping("/search")
    public R<List<ArticleShowVO>>search(String keyword){
        return R.success(articleService.search(keyword));
    }


}

